package com.cndw.kungfu.model.goods.domain;

import com.cndw.kungfu.config.ConstantsModel;
import com.cndw.kungfu.ext.NumberProcesser;
import com.cndw.kungfu.ext.StringProcesser;

/**
 * 物品发放的json配置实体类
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-10-24 下午9:32:16
 */
public class SubPops {
	/**
	 * 道具id
	 */
	private int goodsId;
	/**
	 * 道具数量
	 */
	private int num = 1;
	/**
	 * 是否绑定,默认绑定
	 */
	private int bind = 1;
	/**
	 * 随机的道具id列表
	 */
	private String rantIds;
	/**
	 * 银两
	 */
	private int asset = 0;
	/**
	 * 经验
	 */
	private int exp = 0;
	/**
	 * 元宝奖励
	 */
	private int gold = 0;
	/**
	 * 绑定元宝
	 */
	private int goldBing = 0;

	private int[] rantGoodsIds;

	public SubPops() {

	}

	public SubPops(int goodsId,int num, int asset, int exp) {
		this.goodsId = goodsId;
		this.num = num;
		this.asset = asset;
		this.exp = exp;
	}
	
	public SubPops(int goodsId,int num,int bind){
		this.goodsId = goodsId;
		this.num = num;
		this.bind = bind;
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodId) {
		this.goodsId = goodId;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getBind() {
		return bind;
	}

	public void setBind(int bind) {
		this.bind = bind;
	}

	public String getRantIds() {
		return rantIds;
	}

	public void setRantIds(String rantIds) {
		this.rantIds = rantIds;
		if (rantIds != null && rantIds.length() >= 1) {
			rantGoodsIds = StringProcesser.toIntArray(rantIds);
		}
	}

	public int[] getRantGoodsIds() {
		return rantGoodsIds;
	}

	public void setRantGoodsIds(int[] rantGoodsIds) {
		this.rantGoodsIds = rantGoodsIds;
	}

	public int getAsset() {
		return asset;
	}

	public void setAsset(int asset) {
		this.asset = asset;
	}

	public int getExp() {
		return exp;
	}

	public void setExp(int exp) {
		this.exp = exp;
	}

	public int getGold() {
		return gold;
	}

	public void setGold(int gold) {
		this.gold = gold;
	}
	

	public int getGoldBing() {
		return goldBing;
	}

	public void setGoldBing(int goldBing) {
		this.goldBing = goldBing;
	}

	public SubPops copyByRand() {
		SubPops pops = new SubPops();
		pops.setNum(num);
		pops.setBind(bind);
		pops.setAsset(asset);
		// pops.setGold(gold);
		int index = NumberProcesser.mtRand(rantGoodsIds.length) - 1;
		pops.setGoodsId(rantGoodsIds[index]);
		return pops;
	}

	public SubPops copyByRandConfig() {
		SubPops pops = new SubPops();
		pops.setNum(num);
		pops.setBind(bind);
		pops.setAsset(asset);
		int index = 0;
		if (rantGoodsIds.length == 27) {
			index = NumberProcesser.rateIndex(ConstantsModel.challengeAwardRate);
		} else {
			index = NumberProcesser.mtRand(rantGoodsIds.length) - 1;
		}
		if (index < 0 || index >= rantGoodsIds.length) {
			index = NumberProcesser.mtRand(rantGoodsIds.length) - 1;
		}

		pops.setGoodsId(rantGoodsIds[index]);

		return pops;
	}

}
